<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="求职者电话" prop="seekerTel">
        <el-input
          v-model="queryParams.seekerTel"
          placeholder="请输入要搜索的求职者电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="求职者密码" prop="seekerPwd">
        <el-input
          v-model="queryParams.seekerPwd"
          placeholder="请输入要搜索的求职者密码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="求职者姓名" prop="seekerName">
        <el-input
          v-model="queryParams.seekerName"
          placeholder="请输入要搜索的求职者姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="求职者邮箱" prop="seekerEmail">
        <el-input
          v-model="queryParams.seekerEmail"
          placeholder="请输入要搜索的求职者邮箱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="求职者性别" prop="seekerGender">
        <el-input
          v-model="queryParams.seekerGender"
          placeholder="请输入要搜索的求职者性别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="求职者出生年月" prop="seekerDob">
        <el-date-picker clearable
          v-model="queryParams.seekerDob"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择要搜索的求职者出生年月">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="身份：是否为应届生" prop="seekerIsfreshman">
        <el-input
          v-model="queryParams.seekerIsfreshman"
          placeholder="请输入要搜索的身份：是否为应届生"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学历" prop="seekerEdulvl">
        <el-input
          v-model="queryParams.seekerEdulvl"
          placeholder="请输入要搜索的学历"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="就读时间Study Period" prop="seekerStudyper">
        <el-input
          v-model="queryParams.seekerStudyper"
          placeholder="请输入要搜索的就读时间Study Period"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学校名字" prop="seekerSchname">
        <el-input
          v-model="queryParams.seekerSchname"
          placeholder="请输入要搜索的学校名字"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所修专业" prop="seekerMaj">
        <el-input
          v-model="queryParams.seekerMaj"
          placeholder="请输入要搜索的所修专业"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="当前所在城市" prop="seekerCity">
        <el-input
          v-model="queryParams.seekerCity"
          placeholder="请输入要搜索的当前所在城市"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="期望的工作类型" prop="seekerExpjobtype">
        <el-input
          v-model="queryParams.seekerExpjobtype"
          placeholder="请输入要搜索的期望的工作类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="期望的职位" prop="seekerExppos">
        <el-input
          v-model="queryParams.seekerExppos"
          placeholder="请输入要搜索的期望的职位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="期望的工作地点" prop="seekerExpworkloc">
        <el-input
          v-model="queryParams.seekerExpworkloc"
          placeholder="请输入要搜索的期望的工作地点"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="期望的行业" prop="seekerExpind">
        <el-input
          v-model="queryParams.seekerExpind"
          placeholder="请输入要搜索的期望的行业"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="期望薪资" prop="seekerExpsal">
        <el-input
          v-model="queryParams.seekerExpsal"
          placeholder="请输入要搜索的期望薪资"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="自身优势" prop="seekerAdv">
        <el-input
          v-model="queryParams.seekerAdv"
          placeholder="请输入要搜索的自身优势"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:seeker:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:seeker:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:seeker:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:seeker:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="seekerList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="求职者ID" align="center" prop="seekerId" />
      <el-table-column label="求职者电话" align="center" prop="seekerTel" />
      <el-table-column label="求职者密码" align="center" prop="seekerPwd" />
      <el-table-column label="求职者姓名" align="center" prop="seekerName" />
      <el-table-column label="求职者邮箱" align="center" prop="seekerEmail" />
      <el-table-column label="求职者性别" align="center" prop="seekerGender" />
      <el-table-column label="求职者出生年月" align="center" prop="seekerDob" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.seekerDob, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="身份：是否为应届生" align="center" prop="seekerIsfreshman" />
      <el-table-column label="学历" align="center" prop="seekerEdulvl" />
      <el-table-column label="就读时间Study Period" align="center" prop="seekerStudyper" />
      <el-table-column label="学校名字" align="center" prop="seekerSchname" />
      <el-table-column label="所修专业" align="center" prop="seekerMaj" />
      <el-table-column label="当前所在城市" align="center" prop="seekerCity" />
      <el-table-column label="期望的工作类型" align="center" prop="seekerExpjobtype" />
      <el-table-column label="期望的职位" align="center" prop="seekerExppos" />
      <el-table-column label="期望的工作地点" align="center" prop="seekerExpworkloc" />
      <el-table-column label="期望的行业" align="center" prop="seekerExpind" />
      <el-table-column label="期望薪资" align="center" prop="seekerExpsal" />
      <el-table-column label="自身优势" align="center" prop="seekerAdv" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:seeker:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:seeker:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改求职者信息管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="求职者电话" prop="seekerTel">
          <el-input v-model="form.seekerTel" placeholder="请输入求职者电话" />
        </el-form-item>
        <el-form-item label="求职者密码" prop="seekerPwd">
          <el-input v-model="form.seekerPwd" placeholder="请输入求职者密码" />
        </el-form-item>
        <el-form-item label="求职者姓名" prop="seekerName">
          <el-input v-model="form.seekerName" placeholder="请输入求职者姓名" />
        </el-form-item>
        <el-form-item label="求职者邮箱" prop="seekerEmail">
          <el-input v-model="form.seekerEmail" placeholder="请输入求职者邮箱" />
        </el-form-item>
        <el-form-item label="求职者性别" prop="seekerGender">
          <el-input v-model="form.seekerGender" placeholder="请输入求职者性别" />
        </el-form-item>
        <el-form-item label="求职者出生年月" prop="seekerDob">
          <el-date-picker clearable
            v-model="form.seekerDob"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择求职者出生年月">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="身份：是否为应届生" prop="seekerIsfreshman">
          <el-input v-model="form.seekerIsfreshman" placeholder="请输入身份：是否为应届生" />
        </el-form-item>
        <el-form-item label="学历" prop="seekerEdulvl">
          <el-input v-model="form.seekerEdulvl" placeholder="请输入学历" />
        </el-form-item>
        <el-form-item label="就读时间Study Period" prop="seekerStudyper">
          <el-input v-model="form.seekerStudyper" placeholder="请输入就读时间Study Period" />
        </el-form-item>
        <el-form-item label="学校名字" prop="seekerSchname">
          <el-input v-model="form.seekerSchname" placeholder="请输入学校名字" />
        </el-form-item>
        <el-form-item label="所修专业" prop="seekerMaj">
          <el-input v-model="form.seekerMaj" placeholder="请输入所修专业" />
        </el-form-item>
        <el-form-item label="当前所在城市" prop="seekerCity">
          <el-input v-model="form.seekerCity" placeholder="请输入当前所在城市" />
        </el-form-item>
        <el-form-item label="期望的工作类型" prop="seekerExpjobtype">
          <el-input v-model="form.seekerExpjobtype" placeholder="请输入期望的工作类型" />
        </el-form-item>
        <el-form-item label="期望的职位" prop="seekerExppos">
          <el-input v-model="form.seekerExppos" placeholder="请输入期望的职位" />
        </el-form-item>
        <el-form-item label="期望的工作地点" prop="seekerExpworkloc">
          <el-input v-model="form.seekerExpworkloc" placeholder="请输入期望的工作地点" />
        </el-form-item>
        <el-form-item label="期望的行业" prop="seekerExpind">
          <el-input v-model="form.seekerExpind" placeholder="请输入期望的行业" />
        </el-form-item>
        <el-form-item label="期望薪资" prop="seekerExpsal">
          <el-input v-model="form.seekerExpsal" placeholder="请输入期望薪资" />
        </el-form-item>
        <el-form-item label="自身优势" prop="seekerAdv">
          <el-input v-model="form.seekerAdv" placeholder="请输入自身优势" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSeeker, getSeeker, delSeeker, addSeeker, updateSeeker } from "@/api/system/seeker";

export default {
  name: "Seeker",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 求职者信息管理表格数据
      seekerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        seekerTel: null,
        seekerPwd: null,
        seekerName: null,
        seekerEmail: null,
        seekerGender: null,
        seekerDob: null,
        seekerIsfreshman: null,
        seekerEdulvl: null,
        seekerStudyper: null,
        seekerSchname: null,
        seekerMaj: null,
        seekerCity: null,
        seekerExpjobtype: null,
        seekerExppos: null,
        seekerExpworkloc: null,
        seekerExpind: null,
        seekerExpsal: null,
        seekerAdv: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        seekerTel: [
          { required: true, message: "求职者电话不能为空", trigger: "blur" }
        ],
        seekerPwd: [
          { required: true, message: "求职者密码不能为空", trigger: "blur" }
        ],
        seekerName: [
          { required: true, message: "求职者姓名不能为空", trigger: "blur" }
        ],
        seekerEmail: [
          { required: true, message: "求职者邮箱不能为空", trigger: "blur" }
        ],
        seekerGender: [
          { required: true, message: "求职者性别不能为空", trigger: "blur" }
        ],
        seekerDob: [
          { required: true, message: "求职者出生年月不能为空", trigger: "blur" }
        ],
        seekerIsfreshman: [
          { required: true, message: "身份：是否为应届生不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询求职者信息管理列表 */
    getList() {
      this.loading = true;
      listSeeker(this.queryParams).then(response => {
        this.seekerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        seekerId: null,
        seekerTel: null,
        seekerPwd: null,
        seekerName: null,
        seekerEmail: null,
        seekerGender: null,
        seekerDob: null,
        seekerIsfreshman: null,
        seekerEdulvl: null,
        seekerStudyper: null,
        seekerSchname: null,
        seekerMaj: null,
        seekerCity: null,
        seekerExpjobtype: null,
        seekerExppos: null,
        seekerExpworkloc: null,
        seekerExpind: null,
        seekerExpsal: null,
        seekerAdv: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.seekerId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加求职者信息管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const seekerId = row.seekerId || this.ids
      getSeeker(seekerId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改求职者信息管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.seekerId != null) {
            updateSeeker(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSeeker(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const seekerIds = row.seekerId || this.ids;
      this.$modal.confirm('是否确认删除求职者信息管理编号为"' + seekerIds + '"的数据项？').then(function() {
        return delSeeker(seekerIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/seeker/export', {
        ...this.queryParams
      }, `seeker_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
